#include "freelistblock.h"
#include <stdio.h>

FreeListBlock::FreeListBlock(FILE* device, unsigned long offset) : Block(device, offset)
{
    freeListBlock = new freelist_block_t();
    read(freeListBlock, sizeof(freelist_block_t));
}

FreeListBlock::~FreeListBlock()
{
    delete freeListBlock;
}

ulong FreeListBlock::getDataBlockListSize()
{
    return readUnsignedInteger(freeListBlock->dataBlockListSize, UINT);
}

ulong * FreeListBlock::getFreeListBlockAddresses()
{
    ulong * addresses = new ulong[FREELISTBLOCK_SIZE];

    for(int i = 0; i < FREELISTBLOCK_SIZE; i++)
    {
        addresses[i] = readUnsignedInteger(freeListBlock->dataBlockAddressList[i], UINT);
    }

    return addresses;
}

void FreeListBlock::print()
{
    ulong * addresses = getFreeListBlockAddresses();
    printf("Holds %d entries:\n", getDataBlockListSize());

    for(int i = 0; i < getDataBlockListSize(); i++)
    {
        printf("%d ", addresses[i]);
    }

    printf("\n");
}
